/**
 * 
 */
package cn.sundat.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import cn.sundat.model.User;

/**
 * @author XIN
 *
 */
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {

	public void addUser(User user) {
		getHibernateTemplate().save(user);
		
	}

	public void delUser(User user) {
			getHibernateTemplate().delete(user);
	}

	public boolean editUser(User user) {
		getHibernateTemplate().update(user);
		return false;
	}
	@SuppressWarnings("unchecked")
	public List<User> findUserById(Integer id) {
		return (List<User>) getHibernateTemplate().find("from User where uid=?",id);
		
	}

	@SuppressWarnings("unchecked")
	public List<User> findUserByPage(int nowPage, int pageSize) {
		List<User> useList = (List<User>) getHibernateTemplate().findByCriteria(DetachedCriteria.forClass(User.class), (nowPage - 1) * pageSize, pageSize);
		return useList;
	}

	@SuppressWarnings("unchecked")
	public List<User> findUserByUnameAndPasswd(String uname, String passWd) {
		// TODO Auto-generated method stub
		return  (List<User>) getHibernateTemplate().find("from User where uname=? and upassword=?",uname,passWd);
	}

}
